<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>检测密码</title>
</head>

<body>
    <label>密码:</label> <input type="text" class="value"><button>检测</button>
</body>
<script>
    window.onload = function() {
        var btn = document.querySelector("button");
        btn.addEventListener("click", function(e) {
            var values = document.querySelector(".value");
            var value = values.value;
            var check = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])[a-zA-Z\d]{6,20}$/;
            var isNo = check.test(value);
            console.log(isNo);
            // if (value.length >= 6) {
            //     console.log(123);
            if (isNo) {
                alert("密码格式正确");
            } else {
                alert("密码格式错误");
            }
            // }
        })
    }
</script>

</html>